package com.audaque.springboot.foshanupload.core.util;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class JdkSerializeTool {
    private static Logger logger = LoggerFactory.getLogger(JdkSerializeTool.class);

    public JdkSerializeTool() {
    }

    public static byte[] serialize(Object object) {
        ObjectOutputStream oos = null;
        ByteArrayOutputStream baos = null;

        try {
            baos = new ByteArrayOutputStream();
            oos = new ObjectOutputStream(baos);
            oos.writeObject(object);
            byte[] bytes = baos.toByteArray();
            byte[] var4 = bytes;
            return var4;
        } catch (Exception var14) {
            logger.error(var14.getMessage(), var14);
        } finally {
            try {
                oos.close();
                baos.close();
            } catch (IOException var13) {
                logger.error(var13.getMessage(), var13);
            }

        }

        return null;
    }

    public static <T> Object deserialize(byte[] bytes, Class<T> clazz) {
        ByteArrayInputStream bais = null;

        try {
            bais = new ByteArrayInputStream(bytes);
            ObjectInputStream ois = new ObjectInputStream(bais);
            Object var4 = ois.readObject();
            return var4;
        } catch (Exception var14) {
            logger.error(var14.getMessage(), var14);
        } finally {
            try {
                bais.close();
            } catch (IOException var13) {
                logger.error(var13.getMessage(), var13);
            }

        }

        return null;
    }
}
